package com.alisoft.nano.seda.notification;

import javax.management.Notification;

import com.alisoft.nano.seda.Event;
import com.alisoft.nano.seda.Stage;

public class StageNotification<T> extends Notification {
	private static final long serialVersionUID = 3816839293762553619L;

	public static final String STARTED = "ali.seda.stage.started";
	public static final String PREPOST = "ali.seda.stage.prepost";
	public static final String ACCEPTED = "ali.seda.stage.accepted";
	public static final String PRERUN = "ali.seda.stage.prerun";
	public static final String DONE = "ali.seda.stage.done";
	public static final String STOPPED = "ali.seda.stage.stopped";

	private Stage<T> stage; 
	
	private StageNotification(String type, Event<T> event) {
		super(type, event, 0);
	}
	
	private StageNotification(String type, Stage<T> stage) {
		super(type, stage, 5);
		this.stage = stage;
	}

	@SuppressWarnings("unchecked")
	public Event<T> getEvent() {
		return (Event<T>) this.getSource();
	}
	
	public Stage<T> getStage() {		
		return stage;
	}

	public static <T> StageNotification<T> newPrePost(Event<T> event) {
		return new StageNotification<T>(PREPOST, event);
	}

	public static <T> StageNotification<T> newAccepted(Event<T> event) {
		return new StageNotification<T>(ACCEPTED, event);
	}

	public static <T> StageNotification<T> newPreRun(Event<T> event) {
		return new StageNotification<T>(PRERUN, event);
	}

	public static <T> StageNotification<T> newDone(Event<T> event) {
		return new StageNotification<T>(DONE, event);
	}

	public static <T> StageNotification<T> newStarted(Stage<T> stage) {
		return new StageNotification<T>(STARTED, stage);
	}
	
	public static <T> StageNotification<T> newStopped(Stage<T> stage) {
		return new StageNotification<T>(STOPPED, stage);
	}
}
